﻿/**
 * pixSWX is SWXformat API for pixLib
 *  
 * Copyright © 2007 Laurent Deketelaere, Aral Balkan, Francis Bourre
 * Part of the SWX (SWF Data Exchange Format) project. http://swxformat.org
 * Part of the pixLib project. http://pixlib.org
 *
 * Released under the open source MIT license.
 * http://opensource.org/licenses/mit-license.php
 */import org.triptyk.pixswx.SWXProxy;

import com.bourre.data.collections.Map;
import com.bourre.remoting.RemotingDebug;
import com.bourre.remoting.ServiceProxy;

class org.triptyk.pixswx.SWXProxyLocator 
{
	public var gatewayURL : String;
	private var _m : Map;

	private function SWXProxyLocator()
	{
		_m = new Map();
	}

	public function push( sServiceName : String, service : SWXProxy ) : Void
	{
		if (!gatewayURL) 
		{
			RemotingDebug.ERROR("**Error** GatewayURL is undefined in " + this);
			return;
		} else if ( _m.containsKey(sServiceName) )
		{
			RemotingDebug.ERROR("A service instance is already registered with '" + sServiceName + "' name.");
			return;
		} else
		{
			if (service)
			{
				if (service.getURL() == undefined) service.setURL(gatewayURL);
				_m.put(sServiceName, service);
			} else
			{
				_m.put(sServiceName, new ServiceProxy(gatewayURL, sServiceName));
			}
		}
	}

	public function getService( sName : String  ) : ServiceProxy
	{
		if (!_m.containsKey(sName) ) 
		{
			RemotingDebug.ERROR("Can't find Service instance with '" + sName + "' name.");
		}
		return _m.get(sName);
	}
}